package com.kaka.bus.engine.home.info;

import com.kaka.bus.bean.HttpWrapper;
import com.kaka.bus.bean.NamePhoneBean;
import com.kaka.bus.bean.ProductDetailBean;
import com.kaka.bus.di.DataManager;
import com.kaka.bus.manager.Result;
import com.kaka.bus.manager.T;
import com.kaka.bus.mvp.RxPresenter;
import com.kaka.bus.util.U;

import java.util.List;

import javax.inject.Inject;

/**
 * Created by zhangqi on 2016/10/14.
 * e-mail : ${email}
 * desc :
 */

public class InfoPresenter extends RxPresenter<InfoContract.View> implements InfoContract.Presenter {

    @Inject
    public InfoPresenter(DataManager dataManager) {
        super(dataManager);
    }


    @Override
    public void loadNameAndPhone(String userId, String token) {

        addSubscribe(mDataManager
                .getApi()
                .getNamePhone(userId, token, U.Sign(userId, token))
                .compose(T.D())
                .subscribeWith(new Result<HttpWrapper<NamePhoneBean>>() {
                    @Override
                    protected void onSuccess(HttpWrapper<NamePhoneBean> wrapper) {
                        mView.loadInfoSuccess(wrapper);
                    }
                }));
    }

    @Override
    public void getRegistProduct(String userId, String token) {
        addSubscribe(mDataManager.getApi().getRegisterProduct(userId, token)
                .compose(T.D())
                .subscribeWith(new Result<HttpWrapper<List<ProductDetailBean>>>() {

                    @Override
                    protected void onSuccess(HttpWrapper<List<ProductDetailBean>> listHttpWrapper) {
                        mView.registerProductSuccess(listHttpWrapper);
                    }
                }));
    }

}
